package com.danskin.wechat.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.danskin.wechat.dao.CustInfoExDao;
import com.danskin.wechat.dao.CustShippingDao;
import com.danskin.wechat.entity.CustInfoEx;
import com.danskin.wechat.entity.CustShipping;
import com.danskin.wechat.service.CustShippingService;

@Service
public class CustShippingServiceImpl implements CustShippingService{
	@Autowired
	private  CustShippingDao  custShippingDao;
	@Autowired
	private  CustInfoExDao custInfoExDao;

	@Override
	public void insertCustShipping(String openId, String appId, String address, String city, String district,
			String name, String phone, String province) {
		CustShipping custShipping = new CustShipping();
		CustInfoEx ex = custInfoExDao.queryCustInfoEx(appId,openId);
        if(ex!=null){
        	custShipping.setCustExId(ex.getId());
		}
		custShipping.setConsigneeName(name);
		custShipping.setMobile(phone);
		custShipping.setTelephone("");
		custShipping.setProvince(province);
		custShipping.setCity(city);
		custShipping.setDistrict(district);
		custShipping.setTown("");
		custShipping.setDetailAddress(address);
		custShipping.setIsDefault(1);
		custShippingDao.insertCustShipping(custShipping);
	}

	@Override
	public CustShipping queryCustShipping(String appId, String openId) {
		// TODO Auto-generated method stub
		return custShippingDao.queryCustShipping(appId,openId);
	}

	@Override
	public void updateCustShipping(CustShipping custShipping) {
		// TODO Auto-generated method stub
		custShippingDao.updateCustShipping(custShipping);
	}

	@Override
	public void deleteCustShipping(String openId, String appId) {
		// TODO Auto-generated method stub
		 custShippingDao.deleteCustShipping(openId,appId);
	}
}
